package com.zjut.zs.applyview.action;

import java.io.File;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zjut.an.config.manager.AnConfigManager;
import com.zjut.an.file.dao.AnFile;
import com.zjut.an.file.manager.AnFileManager;
import com.zjut.an.log.dao.AnLog;
import com.zjut.an.log.manager.AnLogManager;
import com.zjut.an.util.module.PageModule;
import com.zjut.an.util.system.SMSHelper;
import com.zjut.an.util.tools.DateUtil;
import com.zjut.an.util.tools.JSONUtilClass;
import com.zjut.an.util.tools.JSONUtilClassTime;
import com.zjut.zs.applyview.dao.ZsApplyView;
import com.zjut.zs.applyview.manager.ZsApplyViewManager;
import com.zjut.zs.coname.dao.ZsCoName;
import com.zjut.zs.coname.manager.ZsCoNameManager;
import com.zjut.zs.excel.tools.ExcelUtils;
import com.zjut.zs.excel.tools.JsGridReportBase;
import com.zjut.zs.excel.tools.TableData;
import com.zjut.zs.hjqk.dao.ZsHjqk;
import com.zjut.zs.hjqk.manager.ZsHjqkManager;
import com.zjut.zs.shhd.dao.ZsShhd;
import com.zjut.zs.shhd.manager.ZsShhdManager;
import com.zjut.zs.user.dao.ZsUser;
import com.zjut.zs.userinfo.dao.ZsUserinfo;
import com.zjut.zs.userinfo.manager.ZsUserinfoManager;
import com.zjut.zs.userstatus.dao.ZsUserStatus;
import com.zjut.zs.userstatus.manager.ZsUserStatusManager;
import com.zjut.zs.util.tools.ZipUtil;
import com.zjut.zs.util.tools.ZsHTMLCreat;
import com.zjut.zs.zxlb.dao.ZsZxlb;
import com.zjut.zs.zxlb.manager.ZsZxlbManager;

public class ZsApplyViewAction extends ActionSupport implements
ServletResponseAware, ServletRequestAware, ModelDriven<ZsApplyView>{

	private HttpServletRequest request;
	private HttpServletResponse response;
	private HttpSession session;
	
	private ZsApplyView obj;
	private Map<String , Object> dataMap;
	private int page = 1, limit = 10;
	private String order;
	private String sort;
	private String search;
	private String rowstr;
	private String searchtype;
	
	@Resource(name = "ZsApplyViewManager")
	private ZsApplyViewManager manager;

	@Resource(name = "ZsCoNameManager")
	private ZsCoNameManager comanager;

	@Resource(name = "ZsUserStatusManager")
	private ZsUserStatusManager zsmanager;

	@Resource(name = "ZsUserinfoManager")
	private ZsUserinfoManager zimanager;

	@Resource(name = "ZsZxlbManager")
	private ZsZxlbManager zxmanager;

	@Resource(name = "ZsShhdManager")
	private ZsShhdManager shmanager;

	@Resource(name = "ZsHjqkManager")
	private ZsHjqkManager hjmanager;

	@Resource(name = "AnConfigManager")
	private AnConfigManager cmanager;
	
	@Resource(name = "ZsHTMLCreat")
	private ZsHTMLCreat html;

	@Resource(name = "DateUtil")
	private DateUtil dateutil;

	@Resource(name = "AnLogManager")
	private AnLogManager logManager;

	@Resource(name = "AnFileManager")
	private AnFileManager fManager;
	
	public String zsApplyViewList() {
		try {
			if (session.getAttribute("admin")!=null) {//只有管理员才允许执行该操作，以免信息泄露
				request.setCharacterEncoding("UTF-8");
				dataMap = new HashMap<String, Object>();			
				PageModule module = manager.getDataByInstance(page, limit, sort, order, obj);
				dataMap.put("rows", module.getObjects());
				dataMap.put("total", module.getTotal()); 
				obj = null; 
			}			
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}
	
	public String zsApplyViewCount() {
		try {
			if (session.getAttribute("admin")!=null) {//只有管理员才允许执行该操作，以免信息泄露
				request.setCharacterEncoding("UTF-8");
				dataMap = new HashMap<String, Object>();			
				int count = manager.getCountByInstance(obj);
				dataMap.put("total", count); 
				obj = null; 
			}			
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}

	public String zsApplyViewCountForReg() {
		try {
			request.setCharacterEncoding("UTF-8");
			dataMap = new HashMap<String, Object>();
			
			String usMobile = request.getParameter("usMobile");

			
			
			obj.setUsMobile(usMobile);// 首先适用zs_user表里的手机匹配
			int count = manager.getCountByInstance(obj);
			System.out.println("##1 "+count);
			if (count<1) {//如果不对，适用导入的InLxdh字段匹配
				obj.setUsMobile(null);
				obj.setInLxdh(usMobile);
				count = manager.getCountByInstance(obj);
				if (count<1) {//如果不对，适用导入的InLxdh2字段匹配
					obj.setInLxdh(null);
					obj.setInLxdh2(usMobile);
					count = manager.getCountByInstance(obj);
				}
			}
			
			dataMap.put("total", count); 
			obj = null; 			
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}

	public String zsApplyViewListSearch() {
		try {
			if (session.getAttribute("admin")!=null) {//只有管理员才允许执行该操作，以免信息泄露
				request.setCharacterEncoding("UTF-8");
				dataMap = new HashMap<String, Object>();
				if ("ab".equals(request.getParameter("searchtype"))) {
					PageModule module = manager.getDataByAB(page, limit, sort, order, Integer.parseInt(request.getParameter("anum")), Integer.parseInt(request.getParameter("bnum")));
					dataMap.put("rows", module.getObjects());
					dataMap.put("total", module.getTotal()); 
				}
				if ("aorb".equals(request.getParameter("searchtype"))) {
					PageModule module = manager.getDataByAorB(page, limit, sort, order, Integer.parseInt(request.getParameter("num")));
					dataMap.put("rows", module.getObjects());
					dataMap.put("total", module.getTotal()); 
				}				
				obj = null; 
			}
			
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}

	
	public String zsApplyView() {
		try {
			request.setCharacterEncoding("UTF-8");
			dataMap = new HashMap<String, Object>();
			String usId = request.getParameter("usId");
			obj = manager.getData(usId);
			dataMap.put("rows", obj);
			obj = null;
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}		
	}

	public void zsApplyViewExcelCheck() throws Exception {
		response.setContentType("application/msexcel;charset=utf-8");
		PrintWriter writer = response.getWriter();
    	writer.write("success");
	}

	public void zsApplyViewExportExcel() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        
	        List list = manager.getDataByInstance(1, 100000, sort, order, obj).getObjects();
	        String title = "花名册";
	        List columns = comanager.getDatasForExcel();
	        String[] hearders = new String[columns.size()+4];
            String[] fields = new String[columns.size()+4];
            ZsCoName co = null;
            for (int i=0; i<columns.size(); i++) {
            	co = (ZsCoName)columns.get(i);
            	hearders[i] = co.getCoCn();
            	fields[i] = co.getCoEn();
            }
            //hearders[hearders.length-4]="报名编号";
			/*
			 * hearders[hearders.length-3]="专项类别"; hearders[hearders.length-2]="社会活动";
			 * hearders[hearders.length-1]="其他获奖";
			 */
            //fields[hearders.length-4]="scColumn10";
			/*
			 * fields[hearders.length-3]="column8"; fields[hearders.length-2]="column9";
			 * fields[hearders.length-1]="column10";
			 */     
            TableData td = this.creatTableData(list, hearders, fields);
            JsGridReportBase report = new JsGridReportBase(request, response);
            report.exportToExcel(title, "admin", td, false);
		}catch(RuntimeException e) {
			e.printStackTrace();
		}
	}
	/*
	public String zsApplyViewExportExcel() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        dataMap = new HashMap<String, Object>();
	        
	        List list = manager.getDataByInstance(1, 100000, sort, order, obj).getObjects();
	        list = this.addOtherColumn(list);
	        
	        dataMap.put("rows", list);
	        return SUCCESS;
		}catch(RuntimeException e) {
			e.printStackTrace();
			return ERROR;
		}
	}*/
	
	public String zsApplyViewExportExcelBySelect() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        dataMap = new HashMap<String, Object>();
	        System.out.println("######################" +rowstr);
	        List<ZsApplyView> list = JSONUtilClassTime.getDTOList(rowstr, ZsApplyView.class);
			list = this.addOtherColumn(list);
			dataMap.put("rows", list);
	        return SUCCESS;
		}catch(RuntimeException e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	private List addOtherColumn(List list) {
		ZsUser zsuser = new ZsUser();
		//for (int i=0; i<list.size();i++) {
        	//String receiveno = html.getReceiveNo(obj.getUsNo());
        	//obj.setScColumn10(receiveno);
			/*
			 * ZsZxlb zxlb = new ZsZxlb(); zsuser.setUsId(obj.getUsId());
			 * zxlb.setZsUser(zsuser); List zxlist = zxmanager.getDataByInstance(1, 100,
			 * null, null, zxlb).getObjects(); if (zxlist!=null && zxlist.size()>0) { String
			 * column8 = ""; for(int j=0; j<zxlist.size(); j++) { zxlb =
			 * (ZsZxlb)zxlist.get(j);
			 * column8+="["+zxlb.getZxType()+"."+zxlb.getZxName()+"."+zxlb.getZxJb()+"."+
			 * zxlb.getZxDate()+"."+zxlb.getZxOrg()+"."+zxlb.getZxDj()+"] "; }
			 * obj.setColumn8(column8); }
			 * 
			 * ZsShhd shhd = new ZsShhd(); shhd.setZsUser(zsuser); List shlist =
			 * shmanager.getDataByInstance(1, 100, null, null, shhd).getObjects(); if
			 * (shlist!=null && shlist.size()>0) { String column9 = ""; for(int j=0;
			 * j<shlist.size(); j++) { shhd = (ZsShhd)shlist.get(j);
			 * column9+="["+shhd.getHdName()+"."+shhd.getHdJs()+"."+shhd.getHdDateStart()+
			 * "-"+shhd.getHdDateEnd()+"."+shhd.getHdOrg()+"] "; } obj.setColumn9(column9);
			 * }
			 * 
			 * ZsHjqk hjqk = new ZsHjqk(); hjqk.setZsUser(zsuser); List hjlist =
			 * hjmanager.getDataByInstance(1, 100, null, null, hjqk).getObjects(); if
			 * (hjlist!=null && hjlist.size()>0) { String column10 = ""; for(int j=0;
			 * j<hjlist.size(); j++) { hjqk = (ZsHjqk)hjlist.get(j);
			 * column10+="["+hjqk.getHjName()+"."+hjqk.getHjJb()+"."+hjqk.getHjDate()+"."+
			 * hjqk.getHjOrg()+"."+hjqk.getHjDj()+"] "; } obj.setColumn10(column10); }
			 */
        //}
		return list;
	}

/*
	public void zsApplyViewExportExcel() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        
	        List list = manager.getDataByInstance(1, 100000, sort, order, obj).getObjects();
	        String title = "花名册";
	        List columns = comanager.getDatasForExcel();
	        String[] hearders = new String[columns.size()+3];
            String[] fields = new String[columns.size()+3];
            ZsCoName co = null;
            for (int i=0; i<columns.size(); i++) {
            	co = (ZsCoName)columns.get(i);
            	hearders[i] = co.getCoCn();
            	fields[i] = co.getCoEn();
            }
            hearders[hearders.length-4]="报名编号";
            hearders[hearders.length-3]="专项类别";
            hearders[hearders.length-2]="社会活动";
            hearders[hearders.length-1]="其他获奖";
            fields[hearders.length-4]="scColumn10";
            fields[hearders.length-3]="column8";
            fields[hearders.length-2]="column9";
            fields[hearders.length-1]="column10";       
            TableData td = this.creatTableData(list, hearders, fields);
            JsGridReportBase report = new JsGridReportBase(request, response);
            report.exportToExcel(title, "admin", td, false);
		}catch(RuntimeException e) {
			e.printStackTrace();
		}
	}*/

/*	public void zsApplyViewExportExcelBySelect() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        
	        String objumniJSON = rowstr;
	        System.out.println("######################" +rowstr);
			List<ZsApplyView> list = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
			
	        String title = "花名册";
	        List columns = comanager.getDatasForExcel();
	        String[] hearders = new String[columns.size()+3];
            String[] fields = new String[columns.size()+3];
            ZsCoName co = null;
            for (int i=0; i<columns.size(); i++) {
            	co = (ZsCoName)columns.get(i);
            	hearders[i] = co.getCoCn();
            	fields[i] = co.getCoEn();
            }
            hearders[hearders.length-4]="报名编号";
            hearders[hearders.length-3]="专项类别";
            hearders[hearders.length-2]="社会活动";
            hearders[hearders.length-1]="其他获奖";
            fields[hearders.length-4]="scColumn10";
            fields[hearders.length-3]="column8";
            fields[hearders.length-2]="column9";
            fields[hearders.length-1]="column10";     
            TableData td = this.creatTableData(list, hearders, fields);
            JsGridReportBase report = new JsGridReportBase(request, response);
            report.exportToExcel(title, "admin", td, false);
		}catch(RuntimeException e) {
			e.printStackTrace();
		}
	}*/
	
	//////////////////////////导出简易excel，无专项类别等内容///////////////////////
	public void zsApplyViewExportExcelSimple() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        
	        List list = manager.getDataByInstance(1, 100000, sort, order, obj).getObjects();
	        String title = "花名册";
	        List columns = comanager.getDatasForExcel();
	        String[] hearders = new String[columns.size()+3];
            String[] fields = new String[columns.size()+3];
            ZsCoName co = null;
            for (int i=0; i<columns.size(); i++) {
            	co = (ZsCoName)columns.get(i);
            	hearders[i] = co.getCoCn();
            	fields[i] = co.getCoEn();
            }
            hearders[hearders.length-4]="报名编号";
            fields[hearders.length-4]="scColumn10";     
            TableData td = this.creatTableDataSimple(list, hearders, fields);
            JsGridReportBase report = new JsGridReportBase(request, response);
            report.exportToExcel(title, "admin", td, false);
		}catch(RuntimeException e) {
			e.printStackTrace();
		}
	}
	
	public void zsApplyViewExportExcelBySelectSimple() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        
	        String objumniJSON = rowstr;
	        System.out.println("######################" +rowstr);
			List<ZsApplyView> list = JSONUtilClassTime.getDTOList(objumniJSON, ZsApplyView.class);
			
	        String title = "花名册";
	        List columns = comanager.getDatasForExcel();
	        String[] hearders = new String[columns.size()];
            String[] fields = new String[columns.size()];
	        //String[] hearders = new String[columns.size()+3];
            //String[] fields = new String[columns.size()+3];
            ZsCoName co = null;
            for (int i=0; i<columns.size(); i++) {
            	co = (ZsCoName)columns.get(i);
            	hearders[i] = co.getCoCn();
            	fields[i] = co.getCoEn();
            }
            //hearders[hearders.length-4]="报名编号";
            //fields[hearders.length-4]="scColumn10";   
            TableData td = this.creatTableDataSimple(list, hearders, fields);
            JsGridReportBase report = new JsGridReportBase(request, response);
            report.exportToExcel(title, "admin", td, false);
		}catch(RuntimeException e) {
			e.printStackTrace();
		}
	}
	
	private TableData creatTableDataSimple(List list, String[] hearders, String[] fields) {
		
		ZsUser zsuser = new ZsUser();
        for (int i=0; i<list.size();i++) {
        	obj = (ZsApplyView)list.get(i);
        	
        	//String receiveno = html.getReceiveNo(obj.getUsNo());
        	//obj.setScColumn10(receiveno);
        	
        }
		TableData td = ExcelUtils.createTableData(list, ExcelUtils.createTableHeader(hearders),fields);
		return td;
	}

	///////////////////////////////////////////////////////////////////
	
	public String zsApplyViewSmsBySelect() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        dataMap = new HashMap<String, Object>();
	        
	        if ("single".equals(request.getParameter("smsType"))) {//单页短信

				String usId = request.getParameter("usId");
				obj = manager.getData(usId);
				String message = request.getParameter("message");
				String mobile=obj.getUsMobile()+";";
				String yzm = cmanager.getSingleConfigInfoByName("验证码前缀");
				String kzm = cmanager.getSingleConfigInfoByName("扩展码");
				String end = SMSHelper.sendSMS(SMSHelper.generateMobiles(mobile.toString()), yzm+message, kzm);
				AnLog log = new AnLog(obj.getUsId(), "短信日志","["+end+"]"+dateutil.getCurrentDate5()+"向"+obj.getUsName()+"("+logManager.subMobile(obj.getUsMobile())+")("+logManager.subIdcard(obj.getUsIdcard())+")"+"发送短信:"+message, dateutil.getCurrentDate5());
				logManager.addData(log);
				dataMap.put("flag", "success");
				dataMap.put("msg", end);
			} else {
				List<ZsApplyView> list = JSONUtilClassTime.getDTOList(rowstr, ZsApplyView.class);
				String message = request.getParameter("message");
				
				StringBuffer mobile = new StringBuffer();
				
				for (ZsApplyView obj:list) {
					mobile.append(obj.getUsMobile()+";");
				}
				String yzm = cmanager.getSingleConfigInfoByName("验证码前缀");
				String kzm = cmanager.getSingleConfigInfoByName("扩展码");
				String end = SMSHelper.sendSMS(SMSHelper.generateMobiles(mobile.toString()), yzm+message, kzm);
				System.out.println("短信发送结束："+dateutil.getCurrentDate5()+" " +end);
				for (ZsApplyView obj:list) {
					AnLog log = new AnLog(obj.getUsId(), "短信日志",dateutil.getCurrentDate5()+"向"+obj.getUsName()+"("+logManager.subMobile(obj.getUsMobile())+")("+logManager.subIdcard(obj.getUsIdcard())+")"+"发送短信:"+message, dateutil.getCurrentDate5());
					logManager.addData(log);
				}
				dataMap.put("flag", "success");
				dataMap.put("msg", end);
			}	     
			return SUCCESS;
		}catch(RuntimeException e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	private TableData creatTableData(List list, String[] hearders, String[] fields) {
		
		ZsUser zsuser = new ZsUser();
        //for (int i=0; i<list.size();i++) {
        	//String receiveno = html.getReceiveNo(obj.getUsNo());
        	//obj.setScColumn10(receiveno);
        	
			/*
			 * ZsZxlb zxlb = new ZsZxlb(); zsuser.setUsId(obj.getUsId());
			 * zxlb.setZsUser(zsuser); List zxlist = zxmanager.getDataByInstance(1, 100,
			 * null, null, zxlb).getObjects(); if (zxlist!=null && zxlist.size()>0) { String
			 * column8 = ""; for(int j=0; j<zxlist.size(); j++) { zxlb =
			 * (ZsZxlb)zxlist.get(j);
			 * column8+="["+zxlb.getZxType()+"."+zxlb.getZxName()+"."+zxlb.getZxJb()+"."+
			 * zxlb.getZxDate()+"."+zxlb.getZxOrg()+"."+zxlb.getZxDj()+"] "; }
			 * obj.setColumn8(column8); }
			 * 
			 * ZsShhd shhd = new ZsShhd(); shhd.setZsUser(zsuser); List shlist =
			 * shmanager.getDataByInstance(1, 100, null, null, shhd).getObjects(); if
			 * (shlist!=null && shlist.size()>0) { String column9 = ""; for(int j=0;
			 * j<shlist.size(); j++) { shhd = (ZsShhd)shlist.get(j);
			 * column9+="["+shhd.getHdName()+"."+shhd.getHdJs()+"."+shhd.getHdDateStart()+
			 * "-"+shhd.getHdDateEnd()+"."+shhd.getHdOrg()+"] "; } obj.setColumn9(column9);
			 * }
			 * 
			 * ZsHjqk hjqk = new ZsHjqk(); hjqk.setZsUser(zsuser); List hjlist =
			 * hjmanager.getDataByInstance(1, 100, null, null, hjqk).getObjects(); if
			 * (hjlist!=null && hjlist.size()>0) { String column10 = ""; for(int j=0;
			 * j<hjlist.size(); j++) { hjqk = (ZsHjqk)hjlist.get(j);
			 * column10+="["+hjqk.getHjName()+"."+hjqk.getHjJb()+"."+hjqk.getHjDate()+"."+
			 * hjqk.getHjOrg()+"."+hjqk.getHjDj()+"] "; } obj.setColumn10(column10); }
			 */
        //}
		TableData td = ExcelUtils.createTableData(list, ExcelUtils.createTableHeader(hearders),fields);
		return td;
	}

	public String zsApplyViewSetTestNo() throws Exception {
		try {
			request.setCharacterEncoding("UTF-8");
	        response.setContentType("application/msexcel;charset=utf-8");
	        dataMap = new HashMap<String, Object>();
			System.out.println("###########################开始编号"+request.getParameter("begin")+request.getParameter("sendStatus"));
			if ("clear".equals(request.getParameter("testnotype"))) {
				//zsmanager.clearTestNo();
				//List list = manager.getDataByInstance(1, 10000, "ussId", "asc", obj).getObjects();
				
				List<ZsApplyView> list = JSONUtilClassTime.getDTOList(rowstr, ZsApplyView.class);
				ZsUserStatus us = null;
				ZsUserinfo ui = null;
				for (int i=0; i<list.size(); i++) {
		        	obj = (ZsApplyView)list.get(i);
		        	System.out.println("#######################清除编号"+i+obj.getUsId());
		        	us = zsmanager.getData(obj.getUssId());
		        	us.setTestNo(null);
		        	zsmanager.updateData(us);
		        	ui = zimanager.getData(obj.getInId());
		        	//ui.setInSg(null);
		        	//zimanager.updateData(ui);
				}
			} else if ("auto".equals(request.getParameter("testnotype"))) {
				String begin = request.getParameter("begin");
		        //List list = manager.getDataByInstance(1, 100000, "ussId", "asc", obj).getObjects();

				List<ZsApplyView> list = JSONUtilClassTime.getDTOList(rowstr, ZsApplyView.class);
		        List<ZsUserStatus> objlist = new ArrayList();
		        ZsUserStatus us = null;
		        for (int i=0; i<list.size(); i++) {
		        	obj = (ZsApplyView)list.get(i);
		        	System.out.println("###########################编号"+i+obj.getUsId());
		        	us = zsmanager.getData(obj.getUssId());
		        	objlist.add(us);
		        }
		        zsmanager.setTestNo(objlist, Integer.parseInt(begin));		        
			} else if ("single".equals(request.getParameter("testnotype"))) {
				zsmanager.getTestNo(zsmanager.getData(manager.getData(request.getParameter("usId")).getUssId()));		        
			}
	        
			obj = null; 
			dataMap.put("flag", "success");
			return SUCCESS;
		}catch(RuntimeException e) {
			e.printStackTrace();
			return ERROR;
		}
	}

//////////////////////////导出考生照片///////////////////////
	public void zsApplyViewExportPhoto() throws Exception {		
		request.setCharacterEncoding("UTF-8");
		response.setContentType("application/msexcel;charset=utf-8");
		List list = manager.getDataByInstance(1, 100000, sort, order, obj).getObjects();
		String zipname = dateutil.getCurrentDate4();
		File outfilePath = new File(cmanager.getSingleConfigInfoByName("网站目录") + "\\file\\" + zipname);
		boolean newjavaFile = outfilePath.mkdir();
		System.out.println(newjavaFile);
		for (int i = 0; i < list.size(); i++) {
			obj = (ZsApplyView) list.get(i);
			try {
				if (null != obj.getInPhoto() && obj.getInPhoto().trim().length() > 0) {
					obj.setInPhoto(obj.getInPhoto().replace("&#x2F;", "\\"));//解决字符过滤引起的问题
					System.out.println("照片地址：" + cmanager.getSingleConfigInfoByName("网站目录") + obj.getInPhoto());
					String filetype = obj.getInPhoto().substring(obj.getInPhoto().lastIndexOf("."));
					File infile = new File(cmanager.getSingleConfigInfoByName("网站目录") + obj.getInPhoto());
					File outfile = new File(outfilePath + "\\" + obj.getUsIdcard() + filetype);
					Files.copy(infile.toPath(), outfile.toPath());
				}
			} catch (RuntimeException e) {
				e.printStackTrace();
				continue;
			}				
		}
		String zipfile = ZipUtil.zip(outfilePath.toPath().toString(),
				cmanager.getSingleConfigInfoByName("网站目录") + "\\file\\", null);
		String zipurl = "/file/" + zipname + ".zip";
		fManager.addData(new AnFile("考生照片"+zipname, zipurl, 0));		
	}

	@Override
	public ZsApplyView getModel() {
		if (null == obj) {
			obj = new ZsApplyView();
		}
		return obj;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		request = arg0;
		session = request.getSession();
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		response = arg0;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	public ZsApplyView getAl() {
		return obj;
	}

	public void setAl(ZsApplyView obj) {
		this.obj = obj;
	}

	public Map<String, Object> getDataMap() {
		return dataMap;
	}

	public void setDataMap(Map<String, Object> dataMap) {
		this.dataMap = dataMap;
	}

	public String getRowstr() {
		return rowstr;
	}

	public void setRowstr(String rowstr) {
		this.rowstr = rowstr;
	}

	public ZsApplyViewManager getManager() {
		return manager;
	}

	public void setManager(ZsApplyViewManager manager) {
		this.manager = manager;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

}
